<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <#assign base=request.contextPath  />
    <link rel="stylesheet" href="${base}/js/layui/css/layui.css?t=1534970980648" media="all">
    <script type="text/javascript" src="${base}/js/zhang.js"></script>
    <script src="${base}/js/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
    <script src="${base}/js/jquery.min.js"></script>

    <style type="text/css">
        form{
            padding:20px;
        }
        .layui-btn-radius{
            border-radius: 5px;
        }
    </style>
</head>
<body>
<form action="" class="layui-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">房间名</label>
            <div class="layui-input-inline">
                <input name="number" lay-verify="required" autocomplete="off" class="layui-input isNull" id="homeName"  type="text">
            </div>
        </div>
    </div>
<#-- <div class="layui-form-item">
     <div class="layui-inline">
         <label class="layui-form-label">选择可见该房间的用户</label>
         <div class="layui-input-inline">
             <select name="city" lay-search="" lay-verify="required" id="home_user" >

             </select>
         </div>
     </div>
 </div>-->

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">房间标签</label>
            <div class="layui-input-inline">
                <select name="city" lay-search="" lay-verify="required" id="homePosition">

                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">房间状态</label>
            <div class="layui-input-block">
                <select name="city" lay-verify="required" id="homeStates">

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-radius" lay-submit="" onclick="insertHome()" type="button" lay-filter=""style="background-color: #0092EF;">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary layui-btn-radius">重置</button>
            </div>
        </div>
    </div>
</form>

<script>
    findState()
    findPosition()
    findUserAll()
    layui.use(['form', 'layedit'], function(){
        var form = layui.form
                ,layer = layui.layer
                ,layedit = layui.layedit

    });





    //查询字典表状态
    function findState(){
        var bas='${base}';
        var homeState=   getDataByCode(bas,"home_stuts");
        for(var i=0;i<homeState.length;i++){
            $("#homeStates").append(
                    '<option value="'+homeState[i].id+'">'+homeState[i].name+'</option>'
            )
        }

    }
    //查询字典表房间朝向
    function findPosition(){
        var bas='${base}';
        var homeState=   getDataByCode(bas,"home_position");
        for(var i=0;i<homeState.length;i++){
            $("#homePosition").append(
                    '<option value="'+homeState[i].name+'">'+homeState[i].name+'</option>'
            )
        }

    }
    //查询所有用户
    function findUserAll(){
        $.ajax({
            type:"POST",
            url:"${base}/user/findUserAll",
            async:false,
            success : function(data){
                for(var i=0;i<data.length;i++){
                    $("#home_user").append(
                            '<option value="'+data[i].id+'">'+data[i].username+'</option>'
                    )
                }
            }
        });

    }

    function insertHome(){
        if(!isNull()){
            return;
        }
        var requstData={};
        requstData.name=$("#homeName").val();
        requstData.roomLabel=$("#homePosition").val();
        requstData.roomStatus=$("#homeStates").val();
        $.ajax({
            type:"POST",
            url:"${base}/room/insertHome",
            // data:{param:JSON.stringify(requstData),userId:$("#home_user").val()},
            data:{param:JSON.stringify(requstData)},
            success : function(data){
                if(data==="true"){
                    layer.msg("添加成功")
                    setTimeout(function(){
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                    parent.initHome();
                    },500)
                }else{
                    layer.msg(data);
                }


            }
        });
    }
</script>
</body>

</html>
